package com.cskaoyan.kpi.area;

import com.cskaoyan.kpi.Summary;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
 * @ClassName DailyAreaReducer
 * @Description: TODO
 * @Author 远志 zhangsong@cskaoyan.onaliyun.com
 * @Date 2023/2/17 15:19
 * @Version V1.0
 **/
public class DailyAreaReducer extends Reducer<Text, Text, Summary, Text> {
    @Override
    protected void reduce(Text key, Iterable<Text> values, Context context) throws IOException, InterruptedException {
        //统计每个省的数量，需要把时间取出来，要不然后面不知道哪一天的数据
        int num = 0;
        String date = null;
        for (Text value : values) {
            if(num == 0){
                date = value.toString();
            }
            num ++;
        }
        Summary dailyArea = new Summary(null, date, "dailyArea", num + "", key.toString());
        context.write(dailyArea, new Text());
    }
}
